package com.wushi.lenovo.asia5b.app_ui.credit.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.NestedScrollView;
import android.view.View;
import android.widget.LinearLayout;

import com.mvp.base.BaseFragmentPagerAdapter;
import com.mvp.base.BaseSimpleFragment;
import com.wushi.lenovo.asia5b.R;
import com.wushi.lenovo.asia5b.app_ui.credit.activity.TopupActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by zhangyuncai on 2019/1/15.
 * ATM充值
 */
public class AtmEbankFragment extends BaseSimpleFragment {

    @BindView(R.id.tab_atmebank)
    TabLayout tabLayout;
    @BindView(R.id.vp_atmebank)
    ViewPager mViewPager;
    @BindView(R.id.ll_atm_notice)
    NestedScrollView ll_atm_notice;
    @BindView(R.id.ll_atm_content)
    LinearLayout ll_atm_content;

    public static Fragment newInstance(Context context) {
        return Fragment.instantiate(context, AtmEbankFragment.class.getName());
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_atmebank;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
        initData();
        initEvent();
    }

    @Override
    protected void lazyFetchData() {
        initData();
    }

    @Override
    protected void initView() {
        final List<String> tabs = new ArrayList<>();
        tabs.add(getString(R.string.topup_atm2));
        tabs.add(getString(R.string.topup_ebanking));
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(AtmFragment.sNewStance(getContext(), AtmFragment.class.getName(), null));
        fragments.add(EBankFragment.sNewStance(getContext(), EBankFragment.class.getName(), null));
        mViewPager.setAdapter(new BaseFragmentPagerAdapter(getChildFragmentManager(), fragments, tabs));
        tabLayout.setupWithViewPager(mViewPager);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initEvent() {

    }

    @OnClick({
            R.id.bt_atm_submit,
            R.id.ll_atm_notice
    })
    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.bt_atm_submit) {
            ll_atm_notice.setVisibility(View.GONE);
            ll_atm_content.setVisibility(View.VISIBLE);
            if (getActivity() != null && getActivity() instanceof TopupActivity) {
                TopupActivity topupActivity = (TopupActivity) getActivity();
                topupActivity.tv_topup_transfer.setText(R.string.topup_transactiondetails);
            }
        } else if (v.getId() == R.id.ll_atm_notice) {

        }
    }
}
